package com.tianfei.crowd.controller;

import com.tianfei.crowd.api.MySQLRemoteService;
import com.tianfei.crowd.constant.CrowdConstants;
import com.tianfei.crowd.entity.vo.PortalTypeVO;
import com.tianfei.crowd.utils.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 *
 * 加载主页面的 controller
 *
 * @author: Herz
 * @date: 2021/7/29 21:16
 */
@Controller
public class PortalController {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String showPortalPage(ModelMap modelMap){

        // 1、调用 mySQLRemoteService 的方法查询首页需要的数据
        ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeVODataRemote();

        // 2、检查查询结果
        if (ResultEntity.SUCCESS.equals(resultEntity.getResult())){

            // 3、获取查询结果数据
            List<PortalTypeVO> list = resultEntity.getData();

            // 4、存入模型
            modelMap.addAttribute(CrowdConstants.ATTR_MESSAGE_PORTAL_DATA, list);

        }

        return "portal";
    }
}
